home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFGraph / Application Source / GraphTestApp.cp < prev    next >
Text File  |  1996-06-15  |  5KB  |  203 lines

  1. // ===========================================================================
  2. //    GraphTestApp.cp                Derived heavily from the Dashboard Starter
  3. // ===========================================================================
  4. //
  5.  
  6. #include "GraphTestApp.h"
  7.  
  8. #include <LApplication.h>
  9. #include <LGrowZone.h>
  10. #include <LWindow.h>
  11. #include <UDrawingState.h>
  12. #include <UMemoryMgr.h>
  13. #include <URegistrar.h>
  14.  
  15. #include "ColumnGraphWindow.h"
  16. #include "BarGraphWindow.h"
  17. #include "StackedBarGraphWindow.h"
  18.  
  19. #ifdef OOF_SmartHeap
  20.     #include "smrtheap.hpp"
  21. #endif
  22.  
  23. // ===========================================================================
  24. //        • Main Program
  25. // ===========================================================================
  26.  
  27. void main()
  28. {
  29.                                     // Set Debugging options
  30.     SetDebugThrow_(debugAction_Alert);
  31.     SetDebugSignal_(debugAction_Alert);
  32.  
  33.     InitializeHeap(3);                // Initialize Memory Manager
  34.                                     // Parameter is number of Master Pointer
  35.                                     //   blocks to allocate
  36.     
  37.                                     // Initialize standard Toolbox managers
  38.     UQDGlobals::InitializeToolbox(&qd);
  39.     
  40.     new LGrowZone(20000);            // Install a GrowZone function to catch
  41.                                     //    low memory situations.
  42.                                     //    Parameter is size of reserve memory
  43.                                     //    block to allocated. The first time
  44.                                     //    the GrowZone function is called,
  45.                                     //    there will be at least this much
  46.                                     //    memory left (so you'll have enough
  47.                                     //    memory to alert the user or finish
  48.                                     //    what you are doing).
  49.     
  50.     GraphTestApp    theApp;            // Create instance of your Application
  51.     theApp.Run();                    //   class and run it
  52. }
  53.  
  54.  
  55. // ===========================================================================
  56. //        • GraphTestApp Class
  57. // ===========================================================================
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        • GraphTestApp
  61. // ---------------------------------------------------------------------------
  62. //    Constructor
  63.  
  64. GraphTestApp::GraphTestApp()
  65. {
  66.     //theDB.useSeparateFiles();
  67.     
  68.     // Open OOFile DBs
  69.     if (dbConnect::fileExists("Databases")) {
  70.         theDB.openConnection("Databases");
  71.     }
  72.     else {
  73.         theDB.newConnection("Databases");
  74.         Students.AddTestData();
  75.         Temperatures.AddTestData();
  76.     }
  77.     Students.setSortOrder(dbSorter() << Students.Name << Students.Subject);
  78.     
  79.     dbView Sview(Students);
  80.     Sview << Students.Name << Students.Subject << Students.Mark;
  81.     
  82.     dbView Tview(Temperatures);
  83.     Tview << Temperatures.Day << Temperatures.Time << Temperatures.Temp;
  84.  
  85.     // OK - Let's get Powerplant to work
  86.     //    Register the functions to create our custom Pane classes
  87.     ColumnGraphWindow::RegisterClass();
  88.  
  89.     // Do the Stuff !
  90.     mCWindow = new ColumnGraphWindow(this, &Sview, "\pStudent Grade Average", 100);
  91.     mBWindow = new BarGraphWindow(this, &Tview, "\pDaily Temperatures");
  92. //    mSBWindow = new StackedBarGraphWindow(this, &Tview, "\pDaily Temperatures");
  93.     mSBWindow2 = new StackedBarGraphWindow(this, &Sview, "\pStudent Grade Average");
  94.  
  95. }
  96.  
  97.  
  98. // ---------------------------------------------------------------------------
  99. //        • ~GraphTest
  100. // ---------------------------------------------------------------------------
  101. //    Destructor
  102.  
  103. GraphTestApp::~GraphTestApp()
  104. {
  105. }
  106.  
  107.  
  108. // ---------------------------------------------------------------------------
  109. //        • ObeyCommand
  110. // ---------------------------------------------------------------------------
  111. //    Respond to commands
  112.  
  113. Boolean
  114. GraphTestApp::ObeyCommand(
  115.     CommandT    inCommand,
  116.     void        *ioParam)
  117. {
  118.     Boolean    cmdHandled = true;
  119.     
  120.     switch (inCommand) {
  121.     
  122.         // +++ Add cases here for the commands you handle
  123.         //        Remember to add same cases to FindCommandStatus below
  124.         //        to enable/disable the menu items for the commands
  125.     
  126.         case cmd_PageSetup:
  127.             DoPageSetup();
  128.             break;
  129.             
  130.         case cmd_Print:
  131.             PrintAll();
  132.             break;
  133.  
  134.         default:
  135.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  136.             break;
  137.     }
  138.     
  139.     return cmdHandled;
  140. }
  141.  
  142.  
  143. // ---------------------------------------------------------------------------
  144. //        • FindCommandStatus
  145. // ---------------------------------------------------------------------------
  146. //    Pass back status of a (menu) command
  147.  
  148. void
  149. GraphTestApp::FindCommandStatus(
  150.     CommandT    inCommand,
  151.     Boolean        &outEnabled,
  152.     Boolean        &outUsesMark,
  153.     Char16        &outMark,
  154.     Str255        outName)
  155. {
  156.     switch (inCommand) {
  157.     
  158.         // +++ Add cases here for the commands you handle.
  159.         //
  160.         //        Set outEnabled to TRUE for commands that can be executed at
  161.         //        this time.
  162.         //
  163.         //        If the associated menu items can have check marks, set
  164.         //        outUsesMark and outMark accordingly.
  165.         //
  166.         //        Set outName to change the name of the menu item
  167.     
  168.         case cmd_Print:
  169.         case cmd_PageSetup:
  170.             outEnabled = true;
  171.             break;
  172.  
  173.         default:
  174.             LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  175.                                 outMark, outName);
  176.             break;
  177.     }
  178. }
  179.  
  180.  
  181. // ---------------------------------------------------------------------------
  182. //        • PrintAll
  183. // ---------------------------------------------------------------------------
  184. void
  185. GraphTestApp::PrintAll()
  186. {
  187.     mCWindow->DoPrinting();
  188.     mBWindow->DoPrinting();
  189.     mSBWindow2->DoPrinting();
  190. }
  191.  
  192.  
  193. // ---------------------------------------------------------------------------
  194. //        • DoPageSetup
  195. // ---------------------------------------------------------------------------
  196. // copied from LDocApplication
  197. void
  198. GraphTestApp::DoPageSetup()
  199. {
  200.     UDesktop::Deactivate();
  201.     UPrintingMgr::AskPageSetup(UPrintingMgr::GetDefaultPrintRecord());
  202.     UDesktop::Activate();
  203. }